#p96
person3 = {
    'Name':'Ford Prefect',
    'Gender':'Male',
    'Occupation':'Researcher',
    'Home Planet':'Betelgeuse Seven'
}
print(person3)

#P99
print(person3['Home Planet'])

#P101
person3['Age'] = 33
print(person3)

#p104
found = {}
found['a'] = 0
found['e'] = 0
found['i'] = 0
found['o'] = 0
found['u'] = 0
print(found)
found['e'] = found['e'] + 1
found['e'] +=1
print(found)

#P108
'''
for k in found:
    print(k,'was found',found[k],'time(s).')


#p109
for k in sorted(found):
    print(k, 'was found', found[k], 'time(s).')


#p110
for k,v in sorted(found.items()):
    print(k, 'was found', found[k], 'time(s).')
'''

'''
#P111
vowels = ['a','e','i','o','u']
word = input("Provide a word to search for vowels:")
found = {}
found['a'] = 0
found['e'] = 0
found['i'] = 0
found['o'] = 0
found['u'] = 0
for letter in word:
    if letter in vowels:
        found[letter] +=1
    for k,v in sorted(found.items()):
        print(k,'was found',v,'time(s).')
'''

#p114
'''
vowels = ['a','e','i','o','u']
word = input("Provide a word to search for vowels:")
found = {}
found['a'] = 0
found['e'] = 0
found['i'] = 0
found['o'] = 0
found['u'] = 0
for letter in word:
    if letter in vowels:
        found[letter] +=1

for k,v in sorted(found.items()):
    print(k,'was found',v,'time(s).')
'''

#p116
fruits = {}
fruits['apple'] = 10
print(fruits)
print('apple' in fruits)
if 'bananas' in fruits:
    fruits['bananas'] += 1
else:
    fruits['bananas'] = 1
print(fruits)
if 'bananas' in fruits:
    fruits['bananas'] += 1
else:
    fruits['bananas'] = 1
print(fruits)
#p119
'''
if 'pears' not in fruits:
    fruits['pears'] = 0
fruits['pears'] += 1
print(fruits)
'''
#setdefault
fruits.setdefault('pears',0)
fruits['pears'] += 1
print(fruits)

#P120
'''
vowels = ['a','e','i','o','u']
word = input("Provide a word to search for vowels:")
found = {}
for letter in word:
    if letter in vowels:
        found.setdefault(letter,0)
        found[letter] +=1
    for k,v in sorted(found.items()):
        print(k,'was found',v,'time(s).')
'''

#p124
vowels = {'a','e','e','i','o','u','u'} #集合的创建1
print(vowels)

vowels2 = set('aeeiouu') #用set函数创建
print(vowels2)

#p125
vowels3 = set('aeiou')
word = 'hello'
u = vowels.union(set(word)) #并集
print(u)
u_list = sorted(list(u))
print(u_list)

#p127
d = vowels3.difference(set(word)) #找出不同的对象
print(d)

#p128
i = vowels3.intersection(set(word))
print(i)

'''
#p130
vowels = set('aeiou')
word = input("provide a word to search for vowels:")
found = vowels.intersection(set(word))
for vowel in found:
    print(vowels)
    print(found)
'''

#P133
vowels4 = ('a','e','i','o','u')
print(vowels4)

#p136
people = {}
people['Ford'] = {
    'Name':'Ford Predect',
    'Gender':'Male',
    'occupation':'Researcher',
    'Home Planet':'Betelgeuse Seven'
}
print(people)

#137
people['Arthur'] = {
    'Name': 'Arthur Dent',
    'Gender': 'Male',
    'occupation': 'Sandwich-Maker',
    'Home Planet': 'Earth'
}
people['Trillian'] = {
    'Name': 'Tricia McMillan',
    'Gender': 'Female',
    'occupation': 'Mathematician',
    'Home Planet': 'Earth'
}
people['Robot'] = {
    'Name': 'Marvin',
    'Gender': 'Unknown',
    'occupation': 'Paranoid Android',
    'Home Planet': 'Earth'
}
print(people)

#p139
import pprint
pprint.pprint(people)

#p141
print(people['Arthur']['occupation'])